<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // get 和 set 可以将class的属性进行监测
        // get监测属性，一旦我们获取的时候就会触发这个方法
        // set监测属性，一旦我们设置这个属性就会触发这个方法 
        class Person{
            constructor( name , age ){
                this.name = name ; 
                this.age = age ; 
            }
            get weight (){
                console.log("获取了体重");
                return "80kg" ; 
            }
            set weight (newWeight){
                console.log("设置属性后会触发这个函数");
                console.log(newWeight);
            }
        }
        let ZhangSan = new Person("张三",20);
        console.log(ZhangSan.weight);
        ZhangSan.weight = "50kg" ;
    </script>
</body>
</html>